<?php

namespace App\Models;

use App\Models\Base\WorkTicket as BaseWorkTicket;

/**
 * 
 *
 * @property int $id
 * @property string $code 工单编号
 * @property int $school_id 学校id
 * @property int $school_user_id 学校用户id
 * @property string $room_number 房间号
 * @property string $contact_name 联系人
 * @property string $contact_tel 联系人电话
 * @property string $content 工单内容
 * @property int|null $work_user_id 维护人员id
 * @property int|null $admin_user_id 客服id
 * @property int $status 状态|100：待处理,101：处理中,102：已处理,103：已取消
 * @property \Illuminate\Support\Carbon|null $finish_at 完成时间
 * @property \Illuminate\Support\Carbon|null $cancel_at 取消时间
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property-read \Dcat\Admin\Models\Administrator|null $adminUser
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\WorkTicketDetail> $details
 * @property-read int|null $details_count
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\WorkTicketImage> $images
 * @property-read int|null $images_count
 * @property-read \App\Models\WorkTicketRating|null $rating
 * @property-read \App\Models\School|null $school
 * @property-read \App\Models\SchoolUser|null $schoolUser
 * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\WorkTicketTransfer> $transfers
 * @property-read int|null $transfers_count
 * @property-read \App\Models\WorkUser|null $workUser
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket query()
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket whereAdminUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket whereCancelAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket whereCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket whereContactName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket whereContactTel($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket whereContent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket whereFinishAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket whereRoomNumber($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket whereSchoolId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket whereSchoolUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket whereWorkUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket withTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|WorkTicket withoutTrashed()
 * @mixin \Eloquent
 */
class WorkTicket extends BaseWorkTicket
{
	protected $fillable = [
		self::CODE,
		self::SCHOOL_ID,
		self::SCHOOL_USER_ID,
		self::ADMIN_USER_ID,
		self::ROOM_NUMBER,
		self::CONTACT_NAME,
		self::CONTACT_TEL,
		self::CONTENT,
		self::WORK_USER_ID,
		self::STATUS,
		self::FINISH_AT,
		self::CANCEL_AT
	];

	public function school()
	{
		return $this->belongsTo(School::class, self::SCHOOL_ID);
	}

	public function schoolUser()
	{
		return $this->belongsTo(SchoolUser::class, self::SCHOOL_USER_ID);
	}

	public function workUser()
	{
		return $this->belongsTo(WorkUser::class, self::WORK_USER_ID);
	}

	public function details()
	{
		return $this->hasMany(WorkTicketDetail::class, WorkTicketDetail::WORK_TICKET_ID, self::ID);
	}

	public function images(){
		return $this->hasMany(WorkTicketImage::class, WorkTicketImage::WORK_TICKET_ID, self::ID);
	}

	public function transfers(){
		return $this->hasMany(WorkTicketTransfer::class, WorkTicketTransfer::WORK_TICKET_ID, self::ID);
	}

	public function rating(){
		return $this->hasOne(WorkTicketRating::class, WorkTicketRating::WORK_TICKET_ID, self::ID);
	}

	public function adminUser(){
		return $this->belongsTo(config('admin.database.users_model'), self::ADMIN_USER_ID);
	}

}
